package com.orange.common.net.ktx

import com.orange.common.net.entity.AppParseException
import rxhttp.wrapper.exception.HttpStatusCodeException

/**
 * Created by Orange on 2022/11/20 14:57.
 * https://juejin.cn/post/6844904100090347528#heading-4
 */

val Throwable.code: Int
    get() =
        when (this) {
            //Http状态码异常
            is HttpStatusCodeException -> this.statusCode
            //业务code异常
            is AppParseException -> this.errorCode.toIntOrNull() ?: -1
            else -> -1
        }

val Throwable.msg: String
    get() = rxHttpThrowableFormatMsg(this)

/**
 * 主要用来格式化网络异常Throwable信息
 */
var rxHttpThrowableFormatMsg :(t: Throwable) -> String = {""}
